<!--v3 realtime ret console -->

<script type="text/javascript" src="../com.atilax.frmwk/jquery-1.11.3.js"></script>


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
 crossorigin="anonymous">

<!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
 crossorigin="anonymous">

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
 crossorigin="anonymous"></script>
<p>
	<p>

		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

		<!--  loading -->
		<link rel="stylesheet" href="dist/ladda-themeless.min.css">
		<script src="dist/spin.min.js"></script>
		<script src="dist/ladda.min.js"></script>



		<div class="panel   panel-default" style="width:95%;margin-left:10px">
			<div class="panel-heading">-----上传升级------------------</div>
			<div class="panel-body">






				<!-- body start -->


				<div style="display:none">
					路径与配置
					<textarea rows="3" cols="200" id="cfgtextbox" style="width:100%;height:800px">
 
 

 
</textarea>
				</div>

				上传升级包：
				<input type="file" name="filex" onchange="upload()" id="filex" style="display:inline" class="btn btn-default" /> &nbsp; &nbsp; &nbsp;
				<img id="loadimg" src="..\com.attilax\loading\loading-0.gif"> 升级包安装起始路径：
				<input type="text" name="jarupzippath" id="jarupzippath" style="width:500px;display:inline" />
				<span id="upaftinfo">
					服务器保存路径：
					<input type="text" name="savepath" id="savepath" style="width:500px;display:inline" /> shell读取编码：
					<input id="encodetxt" list="encode_list" class="s_ipt" value="utf8" maxlength="2550" autocomplete="on" style="width:100px">
					<datalist id="url_list">
						<option label="logcfgfile" value="C:\0wkspc\hislog\src\main\resources\log4j.properties" />
						<option label="logfile" value="C:\0log\hislog.log" />
						<option label="Microsoft" value="http://www.microsoft.com" />
					</datalist>
					<datalist id="encode_list">
						<option label="utf8" value="utf8" />
						<option label="gbk" value="gbk" />

					</datalist>
				</span>
				<button type="button" class="btn btn-success" onclick="btn_click()">
					提交执行更新
				</button>
				<img id="loadimg_exe" src="..\com.attilax\loading\loading_bar.gif" style="display:none">



				<script>
					$("#upaftinfo").hide();
					var testdats = { "dbginfo": ["upzip file准备解压文件:update.bat", "upzip file to dst解压文件到当前目录:c:\\d\\dd2/update.bat", "upzip file准备解压文件:war/", "upzip file to dst解压文件到当前目录:c:\\d\\dd2/war/"] };
					var dbg = testdats.dbginfo;
					//下面使用each进行遍历
					$.each(dbg, function (n, value) {
						console.log(value);
					});
					console.log(dbg.join("\r\n"));


					$("#loadimg").hide();
					function upload() {

						$("#savepath").val("上传中");
						$("#loadimg").show();
						var self = this;

						var fd = new FormData();
						fd.append("serverSavePath", "/home/cnhis/cnhisShell");
						fd.append("upfile", $("#filex").get(0).files[0]);
						$.ajax({
							url: "../UploadServlet1",
							type: "POST",
							processData: false,
							contentType: false,
							data: fd,
							success: function (d) {
								console.log(d);
								console.log("----fini");
								$("#savepath").val(d);
								$("#loadimg").hide();
								$("#upaftinfo").show();
							}
						});


					}


					var console_ret_timer;

					function btn_click() {

						var rztContainId = Math.random();
						$("#loadimg_exe").show();
						$("#editctrl").val("");
						//alert("");
						url = "../autoupSrvV3?cmdtextbox=@savepath@&mode=&cwd=" + $("#cwd").val() + "&cfgtextbox=@cfgtextbox@&cmdFrom=file&encode=@encode@&jarupzippath=@jarupzippath@&rztContainId=" + rztContainId;
						url = url.replace("@savepath@", encodeURIComponent($("#savepath").val()));
						url = url.replace("@cfgtextbox@", encodeURIComponent($("#cfgtextbox").val()));
						url = url.replace("@encode@", $("#encodetxt").val());
						url = url.replace("@jarupzippath@", encodeURIComponent($("#jarupzippath").val()));

						$.get(url, function (result, status, xhr) {
							if (result['@type']) {
								//  @type":"com.attilax.util.RuntimeExceptionAtiVer   
								$("#editctrl").val(JSON.stringify(result));
								$("#loadimg_exe").hide();
								return;
							}

							//   console.log( result.join("\r\n"));
						

						


							$("#loadimg_exe").hide();

							clearTimeout(console_ret_timer);

							//finish last a cat cmd ret
							showConsoleRet_last(rztContainId,function(){
								clearTimeout(console_ret_timer);
								$("#editctrl").val($("#editctrl").val() + "\r\n" + JSON.stringify(result));
								var scrollTop = $("#editctrl")[0].scrollHeight;
								$("#editctrl").scrollTop(scrollTop);
							
							});
						}, "json");


						if (console_ret_timer) {
							clearTimeout(console_ret_timer);
							//clearInterval(console_ret_timer);  
						}
						console_ret_timer = window.setTimeout(
							function () {
								console.log("showConsoleRet...");
								showConsoleRet(rztContainId);
							}
							, 2000);

					}


						function showConsoleRet_last(rztContainId,aftfun) {
						//  http://localhost:1314/hislog/commServletV2?new=xx&class=com.attilax.autoup.autoupdate&method=getRztByContainid&paramtypes=str&args=1213
						// 
						var url = "../commServletV2?new=xx&class=com.attilax.autoup.autoupdate&method=getRztByContainid&paramtypes=str&args=" + rztContainId;

						$.get(url, function (result, status, xhr) {

							$("#loadimg_exe").hide();
							if (result['@type']) {
								//  @type":"com.attilax.util.RuntimeExceptionAtiVer   
								$("#editctrl").val(JSON.stringify(result));

								return;
							}

						 
							if (result.length > 0) {
								$("#editctrl").val($("#editctrl").val() + "\r\n" + result.join("\r\n"));
								var scrollTop = $("#editctrl")[0].scrollHeight;
								$("#editctrl").scrollTop(scrollTop);
							 
							}

								aftfun();
							    return;


						 

						}, "json");


					}


					function showConsoleRet(rztContainId) {
						//  http://localhost:1314/hislog/commServletV2?new=xx&class=com.attilax.autoup.autoupdate&method=getRztByContainid&paramtypes=str&args=1213
						// 
						var url = "../commServletV2?new=xx&class=com.attilax.autoup.autoupdate&method=getRztByContainid&paramtypes=str&args=" + rztContainId;

						$.get(url, function (result, status, xhr) {

							$("#loadimg_exe").hide();
							if (result['@type']) {
								//  @type":"com.attilax.util.RuntimeExceptionAtiVer   
								$("#editctrl").val(JSON.stringify(result));

								return;
							}

							//   console.log( result.join("\r\n"));
							if (result.length ==0) { //finish
							    return;

							}
							if (result.length > 0) {
								$("#editctrl").val($("#editctrl").val() + "\r\n" + result.join("\r\n"));
								var scrollTop = $("#editctrl")[0].scrollHeight;
								$("#editctrl").scrollTop(scrollTop);
							}


							console_ret_timer = window.setTimeout(
								function () {
									showConsoleRet(rztContainId);
								}
								, 2000);

						}, "json");


					}


				</script>


				<textarea rows="40" cols="200" id="editctrl" style="width:100%">
 
运行结果。。。。

 
</textarea>
				<!-- end -->


			</div>
		</div>